﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Transactions;
using IssueTracker.Data;
using IssueTracker.Business.Entity;

namespace IssueTracker.Business.BO
{
    public class ProjectCustomTypeBO
    {
        private ProjectCustomTypeDataAccess da;

        public ProjectCustomTypeBO() 
        {
            da = new ProjectCustomTypeDataAccess();
        }


#region Business Methods

        /// <summary>
        /// Add a new ProjectCustomType
        /// </summary>
        /// <param name="projectCustomType"></param>
        /// <returns></returns>
        public ProjectCustomType AddNew(ProjectCustomType projectCustomType)
        {
            ProjectCustomType returnProjectCustomType;

            projectCustomType.CreationDate = DateTime.Today.Date;

            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    returnProjectCustomType = da.Create(projectCustomType);
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                
            }

            return returnProjectCustomType;

        }

        public ProjectCustomType UpdateProjectCustomType(ProjectCustomType projectCustomType)
        {
            ProjectCustomType returnProjectCustomType;

            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    returnProjectCustomType = da.Update(projectCustomType);
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                
                return returnProjectCustomType;
            }
        }

        public void DeleteProjectCustomType(ProjectCustomType projectCustomType)
        {
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    da.Delete(projectCustomType);
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

        public IEnumerable<ProjectCustomType> ListProjectCustomTypes()
        {
            ProjectCustomTypeDataAccess data = new ProjectCustomTypeDataAccess();

            IEnumerable<ProjectCustomType> returnList = data.List();
            return returnList;
        }

        public ProjectCustomType GetProjectCustomType(int id)
        {
            return da.Retrieve(id);
        }

        public IEnumerable<ProjectCustomType> ListProjectCustomTypesByRef(int reference)
        {
            return da.ListByReferenceId(reference);
        }
#endregion
        
   

    }
}
